package com.codef.sharp.common.core.response;

import com.codef.sharp.common.core.enums.ResponseStatus;

import java.io.Serializable;

/**
 * @author zhanrf
 * @date 2022/1/21 15:07
 */
public class ResponseEntity<T> implements Serializable {
    private String code;

    private String message;

    private T data;

    private ResponseEntity() {}

    public static <T> ResponseEntity<T> success() {
        ResponseEntity<T> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(ResponseStatus.OK.value());
        responseEntity.setMessage(ResponseStatus.OK.getMsg());
        return responseEntity;
    }

    public static <T> ResponseEntity<T> success(T data) {
        ResponseEntity<T> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(ResponseStatus.OK.value());
        responseEntity.setMessage(ResponseStatus.OK.getMsg());
        responseEntity.setData(data);
        return responseEntity;
    }

    public static <T> ResponseEntity<T> error() {
        return error(ResponseStatus.FAIL.value(), ResponseStatus.FAIL.getMsg());
    }

    public static <T> ResponseEntity<T> error(String message) {
        return error(ResponseStatus.FAIL.value(), message);
    }

    public static <T> ResponseEntity<T> error(ResponseStatus responseStatus) {
        return error(responseStatus.value(), responseStatus.getMsg());
    }

    public static <T> ResponseEntity<T> error(ResponseStatus responseStatus, String message) {
        return error(responseStatus.value(), message);
    }

    public static <T> ResponseEntity<T> error(String code, String message) {
        ResponseEntity<T> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(code);
        responseEntity.setMessage(message);
        return responseEntity;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
